package AndroidCases;

import Page.AndroidPages.PO.*;
import io.appium.java_client.MobileElement;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.Arrays;
import java.util.Collection;

@RunWith(Parameterized.class)
public class XueqiuCase {

    MainPage mainpage = new MainPage();

    SearchPage searchPage = new SearchPage();
    StockDetailPage stockDetailPage = new StockDetailPage();



    public String stockName;
    public String count;

    public XueqiuCase(String stockName,String count) {
         this.stockName = stockName;
         this.count = count;
    }

    @Parameterized.Parameters()
    public static Collection<String[]> getParams(){
        String[][] objs = {
                {"中国平安","1"},
                {"拼多多","2"},
                {"蔚来","3"}
        };

        return Arrays.asList(objs);
    }


    @Test
    public void addGuanzhu(){
        ZixuanPage zixuanPage = new ZixuanPage();
        mainpage.zixuan.click();
        zixuanPage.searchButton.click();
        searchPage.searchText.sendKeys(stockName);
        System.out.println("start######");
        if (searchPage.stockNameList.size() >0) {
            searchPage.stockNameList.get(0).click();
        } else
        {
            //默认值
            searchPage.searchText.sendKeys("中国平安");
            searchPage.stockNameList.get(0).click();
        }

//        点击加自选按钮
        stockDetailPage.zixuanButton.click();
//TODO:定义一个元素是否存在的按钮
//        if (stockDetailPage.alertNextButton()){
//            stockDetailPage.alertNextButton.click();
//        }
        stockDetailPage.back.click();

//        点击取消
        searchPage.close.click();

//        进行断言
        Assert.assertEquals(zixuanPage.stockNameList.size(),Integer.parseInt(count));

    }

    @AfterClass
    public static void clearData() {
        ZixuanPage zixuanPage = new ZixuanPage();
        StockManagPage stockManagPage = new StockManagPage();
//        点击右上角编辑按钮
        zixuanPage.editGroup.click();
//         选中所有股票
        for (MobileElement mobileElement: stockManagPage.checkBoxList) {
            mobileElement.click();
        }

//        点击取消关注
        stockManagPage.cancleAttention.click();
//        点击确定
        stockManagPage.alertOK.click();
//        点击完成
        stockManagPage.complete.click();
//        判断此时list为空
        Assert.assertEquals(zixuanPage.stockNameList.size(),0);

    }

}

